//
//  JWTAppTabBarTheme.m
//  JWT
//
//  Created by Apple on 2017/1/1.
//  Copyright © 2017年 com.jwtsoft. All rights reserved.
//

#import "JWTAppTabBarTheme.h"
#import "JWTHomeShowViewController.h"
#import "JWTMysViewController.h"



@implementation JWTAppTabBarTheme
SHARED_INSTANCE_IMPLEMENTATION(JWTAppTabBarTheme);


/**
 自定义tabbar的图片和颜色
 */
- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController{
    UIImage *image = [JWTCommons imageWithColor:RGB_WhiteBackGround size:CGSizeMake(UISCREEN_WIDTH, 40.0f)];
    UIImage *finishedImage = image;
    UIImage *unfinishedImage = image;
    //@"tab_index",
    NSArray *tabBarItemImages = @[@"tab_index",@"tab_person"];
    NSInteger index = 0;
    for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {
        [item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];
        UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_press",
                                                      [tabBarItemImages objectAtIndex:index]]];
        UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",
                                                        [tabBarItemImages objectAtIndex:index]]];
        [item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
        index++;
    }
}


/**
 自定义初始化导航栏的高度，设置后视图初始化坐标（0，64）
 */
- (void)customizeInterfaceUIColor:(UIColor *) color{
    UINavigationBar *navBarAppearance = [UINavigationBar appearance];
    //这里我们设置的是颜色，还可以设置shadow等，具体可以参见api
    //    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    UIImage *backgroundImage = nil;
    NSDictionary *textAttributes = nil;
    UIImage *image =[JWTCommons imageWithColor:HeaderBackground_Color size:(CGSizeMake(UISCREEN_WIDTH, 64.0f))];
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
        backgroundImage = image;
        textAttributes = @{
                           NSFontAttributeName: [UIFont boldSystemFontOfSize:18],
                           NSForegroundColorAttributeName: RGB_WhiteBackGround,
                           };
    } else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
        backgroundImage = image;
        textAttributes = @{
                           UITextAttributeFont: [UIFont boldSystemFontOfSize:18],
                           UITextAttributeTextColor: [UIColor whiteColor],
                           UITextAttributeTextShadowColor: [UIColor clearColor],
                           UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetZero],
                           };
#endif
    }
    [navBarAppearance setBackgroundImage:backgroundImage
                           forBarMetrics:UIBarMetricsDefault];
    [navBarAppearance setTitleTextAttributes:textAttributes];
}


/**
 初始化tabbar视图控制器
 
 */
- (RDVTabBarController*)setupViewControllers {
   
    JWTHomeShowViewController *homeVC = [[JWTHomeShowViewController alloc]init];
    UIViewController *homeNavController = [[UINavigationController alloc]
                                                initWithRootViewController:homeVC];
    
    JWTMysViewController *myVC = [[JWTMysViewController alloc] init];
    UIViewController *myNavController = [[UINavigationController alloc] initWithRootViewController:myVC];
    //homePageNavigationController,
    RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
    [tabBarController setViewControllers:@[homeNavController,
                                           myNavController]];
    
    return tabBarController;
}

/**
 获取导航栏控制器
 */
-(UINavigationController *) getNavController{
    UITabBarController *tabBar = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    UINavigationController *nav = tabBar.selectedViewController;
    return nav;
}

@end
